package first.codeTop.byteDance;

/**
 * @ClassName Leetcode121
 * @description:
 * @author: 荣燊
 * @create: 2021-07-25 14:27
 **/
public class Leetcode121 {
    // 买卖股票的最佳时机,有点傻逼这个问题，他的测试用例很简单，没必要复杂化
    public static void main(String[] args) {
        System.out.println();
    }

    public int maxProfit(int[] prices) {
        int min = prices[0];
        int maxRes = Integer.MIN_VALUE;
        for (int i=1; i<prices.length-1; i++) {
            maxRes = Math.max(maxRes, prices[i]-min);
            min = Math.min(min, prices[i]);
        }
        maxRes = Math.max(maxRes, prices[prices.length-1]-min);
        if (maxRes < 0) {
            return 0;
        }
        return maxRes;
    }
}
